package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jx.model.Goods;
import com.jx.service.GoodsService;
import com.jx.servicrimpl.GoodsServiceImpl;

import net.sf.json.JSONObject;
/**
 *增加配送信息表
 * @author 鄢泽然、
 *
 */
public class AddGoodsController extends HttpServlet {
		GoodsService gs = new GoodsServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub

		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		Goods g = new Goods();
		int id = Integer.parseInt(req.getParameter("oid"));
		String name = req.getParameter("gname");
		String time = req.getParameter("gtime");	
		String state = req.getParameter("gstate");
		String address = req.getParameter("gaddress");
		g.setOid(id);
		g.setGname(name);
		g.setGtime(time);
		g.setGstate(state);
		g.setGaddress(address);
		int i = gs.addGoods(g);
		JSONObject goods = new JSONObject();
		goods.put("msg", i);
		PrintWriter pw = resp.getWriter();
		pw.write(String.valueOf(i));
		pw.flush();
		pw.close();
		
	}
}
